package com.pug.zixun.controller.wechatAccount;

import com.alibaba.fastjson.JSON;
import com.pug.zixun.controller.BaseController;
import lombok.SneakyThrows;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 谢迅
 * @version 1.0
 * @date 2022/12/12 14:56
 */
@RestController
public class MenuController extends BaseController {
    @Resource
    private WxMpService wxMpService;

    @PostMapping("/wechatMenu/load")
    public JSON getMenu() {
        WxMpMenu wxMpMenu = null;
        try {
            wxMpMenu = wxMpService.getMenuService().menuGet();
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
        return JSON.parseObject(wxMpMenu.toJson());
    }

    @SneakyThrows
    @PostMapping("/wechatMenu/creatMenu")
    public String creatMenu(String menus) {
        return wxMpService.getMenuService().menuCreate(menus);
    }


}
